<?php

namespace System\Core;

if (!defined('BASEPATH')) die('Access Denied.');

/**
 * µMVC Framework (c) 2011.
 * 
 * PHP5 MVC Framework software for PHP 5.2.17 or later
 * 
 * @package         µMVC
 * @filename        system/core/autoloader.class.php
 * @copyright       Lanz (c) 2011.
 * 
 */

/**
 * Autoloader class
 * This autoloads any .class.php file included in the System,
 * other types of files will still need to be loaded manually.
 * 
 * @package         µMVC
 * @subpackage      Core
 * @category        System
 */
class Autoloader
{

    function __construct()
    {
        // Set up the autoloader right away.
        spl_autoload_register(array($this, '_autoload'));
        
        Log::instance()->write(Log::DEBUG, 'Autoloader Class Initialized.');        
    }

    protected function _autoload($className)
    {
        $className = strtolower($className);

        // Check where the class is located based on the namespace and 
        // construct the appropriate path.
        if (strpos($className, 'system\\') !== FALSE)
        {
            $className = substr($className, 7);
            $className = BASEPATH . str_replace('\\', DS, $className) . '.class.php';
        }

        require_once $className;
    }

}

?>
